package com.hafu.swing;
import com.hafu.service.CourseService;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AuditCourseDialog extends JDialog {
    private CourseService courseService;
    private String courseId;

    public AuditCourseDialog(JFrame parent, CourseService courseService, String courseId) {
        super(parent, "审核课程", true);
        this.courseService = courseService;
        this.courseId = courseId;
        setSize(300, 150);
        setLocationRelativeTo(parent);

        JPanel panel = new JPanel(new GridLayout(2, 1, 10, 10));
        JButton approveButton = new JButton("通过");
        JButton rejectButton = new JButton("拒绝");

        panel.add(approveButton);
        panel.add(rejectButton);
        add(panel);

        // 审核通过事件
        approveButton.addActionListener(e -> {
            if (courseService.auditCourse(courseId, "已通过")) {
                JOptionPane.showMessageDialog(this, "审核通过成功", "成功", JOptionPane.INFORMATION_MESSAGE);
                dispose();
            } else {
                JOptionPane.showMessageDialog(this, "审核失败", "错误", JOptionPane.ERROR_MESSAGE);
            }
        });

        // 拒绝审核事件
        rejectButton.addActionListener(e -> {
            if (courseService.auditCourse(courseId, "已拒绝")) {
                JOptionPane.showMessageDialog(this, "审核拒绝成功", "成功", JOptionPane.INFORMATION_MESSAGE);
                dispose();
            } else {
                JOptionPane.showMessageDialog(this, "操作失败", "错误", JOptionPane.ERROR_MESSAGE);
            }
        });
    }
}